import type { UnwrapRef } from "vue";
import { reactive } from "vue";

export const basicModalProps = {
  open: {
    type: Boolean,
    default: false,
  },
};

export const basicModalEmits = {
  "update:open": (isOpen: boolean) => typeof isOpen,
  clear: () => true,
  success: () => true,
};

export function useModalToggle<T>() {
  const modalToggleInfo = reactive<{
    toggle: boolean;
    record: Partial<T>;
  }>({
    toggle: false,
    record: {},
  });

  function onOpenModal(records?: Partial<T>) {
    if (records !== void 0) {
      modalToggleInfo.record = records as UnwrapRef<Partial<T>>;
    }
    modalToggleInfo.toggle = true;
  }

  return {
    onOpenModal,
    modalToggleInfo,
  };
}
